<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents'); ?>
<script type="text/javascript">
get_check = function(){
	var ids = '';
	$("#list").find("input[type='checkbox']").each(function(){
		if ($(this).is(":checked"))
		{
			if (ids)
			{
				ids += ',';
			}
			ids += $(this).val();
		}
	});
	return ids;
};
$(function(){
	$(".datepicker").datepicker({dateFormat:'yy-mm-dd',changeMonth:true});
	$(".detail").colorbox({width:"90%", height:"70%", iframe:true});
	$("#check_all").click(function(){
		if ($(this).is(":checked"))
		{
			$(".list_table input[type='checkbox']").attr("checked", true);
		}
		else
		{
			$(".list_table input[type='checkbox']").attr("checked", false);
		}
	});
	$("#assigned_btn").click(function(){
		var ids = get_check();
		if (ids.length == 0)
		{
			alert("请选择订单");
			return false;
		}
		if ( ! confirm('确定审核所选的订单？'))
		{
			return false;
		}
		window.location.href="<?=url('purchase::Order/Audit')?>&ids=" + ids;
	});
});
</script>
<fieldset><legend>查询条件</legend>
<form action="" method="get">
<? include(Q::ini('custom_system/elements_dir') . 'searchform_element.php');?>
<table class="form_table">
<tr>
	<th>采购日期</th>
	<td>
		<input type="text" name="begin_purchase_time" class="datepicker" value="<?=isset($_GET['begin_purchase_time'])?$_GET['begin_purchase_time']:''?>" /> to
		<input type="text" name="end_purchase_time" class="datepicker" value="<?=isset($_GET['end_purchase_time'])?$_GET['end_purchase_time']:''?>" />
	</td>
</tr>
<tr>
	<th>采购单号</th>
	<td><input type="text" name="purchase_order_number" value="<?=isset($_GET['purchase_order_number']) ? $_GET['purchase_order_number'] : ''?>" /></td>
</tr>
<tr>
	<th>产品编号</th>
	<td><input type="text" name="product_basic_number" value="<?=isset($_GET['product_basic_number']) ? $_GET['product_basic_number'] : ''?>" /> 输入产品编号后六位例如：000001</td>
</tr>
<tr>
	<th>采购人员</th>
	<td>
		<select name="purchase_user_id">
			<option value="">请选择..</option>
			<?foreach ($user as $u):?>
			<option value="<?=$u['id']?>" <?if (isset($_GET['purchase_user_id'])&&$_GET['purchase_user_id']==$u['id'])echo "selected='selected'"?>><?=$u['name']?></option>
			<?endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<th>仓库</th>
	<td>
		<select name="warehouse_id">
			<option value="">请选择..</option>
			<?foreach ($warehouse as $w):?>
			<option value="<?=$w['id']?>" <?if (isset($_GET['warehouse_id'])&&$_GET['warehouse_id']==$w['id'])echo "selected='selected'"?>><?=$w['name']?></option>
			<?endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<td></td>
	<td><input type="submit" class="button" value="查询" /></td>
</tr>
</table>
</form>
</fieldset>

<table id="list" class="list_table" width=100%>
	<tr>
		<th width="30"></th>
		<th>采购单号</th>
		<th>所属仓库</th>
		<th>采购日期</th>
		<th>采购人</th>
		<th>预计总价</th>
		<th>实际总价</th>
		<th>状态</th>
		<th width="120">操作</th>
	</tr>
	<?foreach ($purchase_order as $po):?>
	<tr>
		<td><input type="checkbox" value="<?=$po['id']?>" /></td>
		<td><a class="detail" href="<?=url('Purchase::Order/Detail', array('id'=>$po['id']))?>"><?=$po['number']?></a></td>
		<td><?=$po['warehouse_name']?></td>
		<td><?=substr($po['purchase_time'], 0, 10)?></td>
		<td><?=$po['purchase_user_name']?></td>
		<td><?=sprintf('%.2f', $po['budget_amount'])?></td>
		<td><?=sprintf('%.2f', $po['actual_amount'])?></td>
		<td><?=Helper_BSS_Normal::getIniOne('purchase_order_status', 'value', $po['status'], 'name')?></td>
		<td><a href="<?=url('Purchase::Order/Audit', array('ids'=>$po['id']))?>">审核通过</a></td>
	</tr>
	<?endforeach;?>
</table>
<?=$page?>
<table class="list_table">
<tr>
	<td rowspan="5"><label><input type="checkbox" id="check_all" />全选</label></td>
	<td align="left"><input type="button" class="button" id="assigned_btn" value="批量审核" /></td>
</tr>
</table>
<?php $this->_endblock();?>